package com.ianmoone.JZOF;

import java.util.Scanner;

public class ZHTest1 {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String string = in.nextLine();
		char[] charArray = string.toCharArray();
		int mid = charArray.length/2;
		int cMax = 0;
		int dMax = 0;
		int cNum = 0;
		int dNum = 0;
		int countC = 0;
		int countD = 0;
		for (int i = 0; i < charArray.length; i++) {
			if (charArray[i]=='C') {
				cMax++;
			}else {
				dMax++;
			}
		}
		//countC
		int indexC=0;
		for (int i = 0; i < charArray.length; i++) {
			if (charArray[i]=='C') {
				cNum++;
				if (i != indexC) {
					countC += i-indexC;
				}
				indexC++;
			}else {
				dNum++;
			}
			if (cNum == cMax) {
				break;
			}
		}
		//countD
		int indexD=0;
		cNum = 0;
		dNum = 0;
		for (int i = 0; i < charArray.length; i++) {
			if (charArray[i]=='D') {
				dNum++;
				if (i != indexD) {
					countD += i-indexD;
				}
				indexD++;
			}else {
				cNum++;
			}
			if (dNum == dMax) {
				break;
			}
		}		
		
		System.out.println(Math.min(countC, countD));
	}
}
